<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/Public/foundation/foundation.min.css">
    <script src="/Public/jquery/jquery.min.js"></script>
    <script src="/Public/foundation/foundation.min.js"></script>
    <script src="/Public/foundation/modernizr.js"></script>

    <!--<script src="/Public/jquery/plugin"></script>-->
    <link rel="stylesheet" href="http://static.runoob.com/assets/foundation-icons/foundation-icons.css">
</head>
<body>
<nav class="top-bar" data-topbar>
    <ul class="title-area">
        <li class="name">
            <h1><a href="#">后台管理</a></h1>
        </li>
    </ul>
    <section class="top-bar-section">
        <ul class="right">
                <li><a href="">欢迎<?php echo (session('name')); ?></a></li>
                <li><a href="<?php echo U('./Sys/Login/doLogout');?>">退出</a></li>
        </ul>

    </section>
</nav>
<div>
    <div class="small-2 columns">
        <?php if(is_array($locks)): $i = 0; $__LIST__ = $locks;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$menu): $mod = ($i % 2 );++$i;?><ul class="side-nav">
                <li><a href="http://127.0.0.1/index.php/<?php echo ($menu["url"]); ?>" target="<?php echo ($menu['target']==0?'_self':'_blank'); ?>"><?php echo ($menu["mname"]); ?></a></li>
            </ul><?php endforeach; endif; else: echo "" ;endif; ?>
    </div>
    <div class="small-10 columns">
        
    <table  id="teaTbl">
        <thead>
        <tr>
            <th><input  onclick="selectAll(this)" type="checkbox"></th>
            <th>编号</th>
            <th>姓名</th>
            <th>邮箱</th>
            <th>手机</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <?php if(is_array($teacher)): $i = 0; $__LIST__ = $teacher;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$v): $mod = ($i % 2 );++$i;?><tr id="row_<?php echo ($v["teacher_id"]); ?>">
                <td><input class="slct" type="checkbox" value="<?php echo ($v["teacher_id"]); ?>"></td>
                <td><?php echo ($v["teacher_id"]); ?></td>
                <td><input name="tname" class="a" disabled type="text" value="<?php echo ($v["tname"]); ?>"></td>
                <td><input name="email" class="a" disabled type="text" value="<?php echo ($v["email"]); ?>"></td>
                <td><input name="mtel" class="a" disabled type="text" value="<?php echo ($v["mtel"]); ?>"></td>
                <td>
                    <button onclick="edit('row_<?php echo ($v["teacher_id"]); ?>')" class="button tiny edit">编辑</button>
                    <button onclick="save('<?php echo ($v["teacher_id"]); ?>')" style="display:none" class="button tiny save">保存</button>
                </td>
            </tr><?php endforeach; endif; else: echo "" ;endif; ?>
        </tbody>
    </table>
        <div>
            <span><?php echo ($page); ?></span>
        </div>
        <a class="button tiny" href="<?php echo U('addTeacher');?>">添加</a>
        <button onclick="unSelect()" class="button tiny">反选</button>
        <button onclick="delLot()" class="button tiny">删除(批量)</button>

<script>
    function edit(rowid) {
        $('#'+rowid+' .a').prop('disabled',false);
        $('#'+rowid+' .edit').hide();
        $('#'+rowid+' .save').show();
        //console.log('#'+id);exit;
    }
    function save(id) {
        $('#row_'+id+' .a').prop('disabled',true);
        $('#row_'+id+' .edit').show();
        $('#row_'+id+' .save').hide();

        var data = {
            teacher_id:id,
            tname:$('#row_'+id+' [name=tname]').val(),
            email:$('#row_'+id+' [name=email]').val(),
            mtel:$('#row_'+id+' [name=mtel]').val(),
        }

        $.post('<?php echo U("doEditTeacher");?>',data,function (data) {
            if(data.error!==0){
                alert(data.msg);
            }
        });

    }
    //全选
    function selectAll(obj) {
        $('#teaTbl tbody .slct').prop('checked',$(obj).prop('checked'));
    }
    //反选
    function unSelect() {
        $('#teaTbl tbody .slct').map(function(){
            $(this).prop('checked',!$(this).prop('checked'));
        });
    }

    //批量删除
    function delLot() {//you
        if(!confirm('确认批量删除吗')){
            return;
        }
        var ids = $('#teaTbl tbody .slct:checked').map(function () {
            $(this).parent().parent().remove();
            return $(this).val();
        });
        ids  = ids.get().join();
        $.post('<?php echo U("doDelTeacher");?>',{ids:ids},function (data) {
            alert(data.msg);
        });
    }

</script>

    </div>
</div>
</body>
</html>